package com.healthcare;

import java.io.IOException;
import java.io.PrintWriter;
import java.rmi.RemoteException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.mail.Message;
import javax.mail.Transport;
import javax.mail.internet.MimeMessage;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import webservices.HealthCareServerProxy;

/**
 * Servlet implementation class AddDoctorList
 */
public class DocUserPostList extends HttpServlet {
        private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DocUserPostList() {
        super();
        // TODO Auto-generated constructor stub
    }

        /**
         * @return 
         * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                // TODO Auto-generated method stub
                //String username1 = request.getParameter("data");
                String docid = request.getSession().getAttribute("docid").toString();
                String userid = null;
                 userid = (String) request.getSession().getAttribute("userids");
                 
                 String username2 = request.getParameter("userValue");
                 //System.out.println("inside DocUserPostList doGet java 1234" + username1);
                 System.out.println("inside DocUserPostList doGet java 1234" + userid);

            //    System.out.println("inside doGet" + userid);
                request.setAttribute("userid", userid);
                RequestDispatcher dispatcher = request.getRequestDispatcher("/DocUserListPosts.jsp");
                dispatcher.forward(request, response);
           
                
        }

        /**
         * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                // TODO Auto-generated method stub
                
                System.out.println("inside comment");
                //if((request.getParameter("cmt")!= null))
                //{
                String user=request.getSession().getAttribute("docname").toString();
                        String data = request.getParameter("data").trim();
                        System.out.println("inside comment1");
                        String id = data.substring(0, 1);
                        String comment = data.substring(3).trim();
                        
                        //String row = "name:12345";
                        String[] columns = data.split("\\$");
                        assert columns.length == 3;
                        String comment1 = columns[0].trim();
                        String id1= columns[1];
                        String username = columns[2];
                        //int id1 = Integer.parseInt(columns[0]);
                        
                        //posts = result.split("\\$");
                        //posts = result.split("\\$");
                         DateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
                                Date date = new Date();
                        //String id = request.getParameter("<%=allposts[4]%> ");
                        System.out.println("comment" +comment1);
                        System.out.println("id" +id1);
                        System.out.println("user" +user);
                        System.out.println("username" +username);
                        //System.out.println("id" +id);
                        //System.out.println("hi");
                        //int postId = Integer.parseInt(prodName);
                        //Boolean postStatus = false;
                        //String status = "false";
                                        //User user = new User(inputfname, inputLastName, inputEmail, inputAge,
                                                //      inputGender, inputPassword);
                                        HealthCareServerProxy proxy = new HealthCareServerProxy();
                                proxy.savedocUserComment(id1, comment1, user, dateFormat.format(date));
                                        RequestDispatcher dispatcher = request.getRequestDispatcher("/DocUserListPosts.jsp");
                                        //System.out.println("inside the delet");
                                        //status="done";
                                        //request.setAttribute("status", status);
                                        
                                   dispatcher.forward(request, response);


                                
                        
                
        }

}